package com.wenwei.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.google.gson.JsonObject;
import com.wenwei.net.ApiManager;
import com.wenwei.net.BaseSubscriber;
import com.wenwei.parking.BaseActivity;
import com.wenwei.parking.R;
import com.wenwei.utils.UserStringUtils;

import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by nidalee on 2017/10/11.
 */

public class SuggestionActivity extends BaseActivity {
    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.suggestion_et)
    EditText suggestionEt;
    @Bind(R.id.suggestion_btn)
    TextView suggestionBtn;

    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_suggestion;
    }

    @Override
    protected void initView() {
        super.initView();
        baseTitle.setText("意见反馈");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.base_back, R.id.suggestion_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.base_back:
                finish();
                break;
            case R.id.suggestion_btn:
                if(suggestionEt.getText().toString().equals("")){
                    showToast("您还没有填写反馈内容哦");
                    return;
                }
                addOpinion();
                break;
        }
    }

    private BaseSubscriber<Object> opinionSb;
    private void addOpinion(){
        opinionSb = new BaseSubscriber<Object>(mContext,true,"请稍后") {
            @Override
            public void onSuccess(Object o) {

                showToast("感谢您的反馈，再见。");
                finish();
            }
        };
        try{
            JSONObject jb = new JSONObject();
            jb.put("userId", UserStringUtils.getUserId(mContext));
            jb.put("content",suggestionEt.getText().toString());
            ApiManager.getInstance().addOpinion(opinionSb,jb.toString());
        }catch (Exception e){

        }
    }
}
